use actix_web::http::StatusCode;
use actix_web::web;
use chrono::NaiveDateTime;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Debug, Clone,sqlx::FromRow)]
pub struct Course {
    pub teacher_id: i32,
    pub id: i32,
    pub name: String,
    pub time: Option<NaiveDateTime>,
    // pub description: Option<String>,
    // pub format: Option<String>,
    // pub structure: Option<String>,
    // pub duration: Option<String>,
    // pub price: Option<i32>,
    // pub language: Option<String>,
    // pub level: Option<String>
    
}
// impl Serialize for Course {
//     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
//     where
//         S: Serializer,
//     {
//         let mut state = serializer.serialize_struct("Course", 4)?;
//         state.serialize_field("teacher_id", &self.teacher_id)?;
//         state.serialize_field("id", &self.id)?;
//         state.serialize_field("name", &self.name)?;
//         state.serialize_field("time", &self.time)?;
//         state.end()
//     }
// }

impl From<web::Json<Course>> for Course {
    fn from(course: web::Json<Course>) -> Self {
        // Course {
        //     teacher_id: course.teacher_id,
        //     id: course.id,
        //     name: course.name.clone(),
        //     time: course.time,
        // }
        course.into_inner()
    }
}


#[derive(Deserialize, Debug, Clone)]
pub struct CreateCourse{
    pub teacher_id: i32,
    pub name: String,
    // pub description: Option<String>,
    // pub format: Option<String>,
    // pub structure: Option<String>,
    // pub duration: Option<String>,
    // pub price: Option<i32>,
    // pub language: Option<String>,
    // pub level: Option<String>
}

impl From<web::Json<CreateCourse>> for CreateCourse {
    fn from(course: web::Json<CreateCourse>) -> Self {
        course.into_inner()
    }
}

#[derive(Deserialize, Debug, Clone)]
pub struct UpdateCourse{
    pub name: Option<String>,
    // pub description: Option<String>,
    // pub format: Option<String>,
    // pub structure: Option<String>,
    // pub duration: Option<String>,
    // pub price: Option<i32>,
    // pub language: Option<String>,
    // pub level: Option<String>
}

impl From<web::Json<UpdateCourse>> for UpdateCourse {
    fn from(course: web::Json<UpdateCourse>) -> Self {
        course.into_inner()
    }
}
